package com.fulihui.wgj.consumer.service.impl;


import com.fulihui.wgj.consumer.config.property.LibyProperties;
import com.fulihui.wgj.consumer.service.ExternalSystemService;
import com.fulihui.wgj.facade.dto.NotifyUserActivityDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.HashMap;

/**
 * @author: LiuJie
 * @version: 2018/7/3 9:34
 * @description:
 */
@Service
@Slf4j
public class ExternalSystemServiceImpl implements ExternalSystemService {
    @Autowired
    LibyProperties libyProperties;
    @Autowired
    RestTemplate restTemplate;
    @Override
    public void qrsceneNotifyTheUser(NotifyUserActivityDTO notifyUserActivity) {
        if (null != notifyUserActivity) {
            HashMap<String, Object> params = new HashMap<>();
            params.put("access_token", libyProperties.getAccessToken());
            params.put("datas", Collections.singletonMap("request", notifyUserActivity));
            try {
                String res = restTemplate.postForObject("http://" + libyProperties.getHost() + "/" + libyProperties.getQrsceneNotifyUser(), params, String.class);
                if (StringUtils.isNotBlank(res)) {
                    log.info("调用接口扫渠道二维码通知用户response={}", res);
                } else {
                    log.error("调用接口扫渠道二维码通知用户错误,返回结果为空");
                }
            } catch (Exception e) {
                log.error("调用接口扫渠道二维码通知用户错误",e);
            }
        }
    }
}
